import request from '@/util/request/index'
import type {
  MusicInfo,
  MusicDetail,
  LyricRes,
  PersonalizedRes,
  RootTopList,
  RootTopArtist,
  RootTags,
  RootTagPlaylist,
} from '@/types/song/index'
import type { TopArtistQuery, KindPlaylistQuery } from '@/types/common/common'

/**
 * 检查歌曲是否能播放
 * @param id
 * @returns
 */
export const checkIsCanPlay = async (id: number) => {
  return await request.get<{ success: boolean; message: string }>(`/check/music?id=${id}`)
}

/**
 * 获取音乐源信息
 * @param id
 * @returns
 */
export const getMusicSource = async (id: number) => {
  return await request.get<MusicInfo>(`/song/url?id=${id}`)
}

/**
 * 获取歌曲详情
 * @param id
 * @returns
 */
export const getMusicDetail = async (id: number) => {
  return await request.get<MusicDetail>(`/song/detail?ids=${id}`)
}

/**
 * 获取歌词
 * @param id
 * @returns
 */
export const getLyric = async (id: number) => {
  return await request.get<LyricRes>(`/lyric?id=${id}`)
}

/**
 * 获取推荐歌单
 * @param limit
 * @returns
 */
export const getRecommend = async (limit: number = 10) => {
  return await request.get<PersonalizedRes>(`/personalized?limit=${limit}`)
}

/**
 * 获取推荐新音乐
 * @returns
 */
export const getRecommendNewSong = async () => {
  return await request.get(`/personalized/newsong`)
}

/**
 * 获取排行详情
 * @param timeStamp
 * @returns
 */
export const getTopListData = async () => {
  return await request.get<RootTopList>(`/toplist/detail`)
}

/**
 * 获取歌手列表
 * @param param
 * @returns
 */
export const getArtistList = async ({ type, area, initial, limit, offset }: TopArtistQuery) => {
  return await request.get<RootTopArtist>(
    `artist/list?type=${type}&area=${area}&initial=${initial}&limit=${limit}&offset=${offset}`
  )
}

/**
 * 获取歌单标签
 * @returns
 */
export const getPlaylistTags = async () => {
  return await request.get<RootTags>(`/playlist/highquality/tags`)
}

/**
 * 获取分类歌单
 * @param param0
 * @returns
 */
export const getKindPlayList = async ({ limit, before, cat }: KindPlaylistQuery) => {
  return await request.get<RootTagPlaylist>(`/top/playlist/highquality?limit=${limit}&before=${before}&cat=${cat}`)
}
